home *** CD-ROM | disk | FTP | other *** search
- #import "aGroup.h"
- #import "aGroup-inter.h"
- #import "TessSketch.h"
- #import "Underlay.h"
- #import "GeneratorOverlay.h"
-
- @implementation aGroup
-
- +new
- {
- self = [super new];
- [self setScaling: 1.0 : 1.0];
- [self setAutosizing: NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE];
- return self;
- }
-
- + setup
- {
- GroupSetup(); // call only once
- return self;
- }
-
- - drawSelf:(const NXRect *)rects :(int)rectCount
- {
- [self clip: GENOFFT : GENOFFT ];
- [[genovly getImage] composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
- return self;
- }
-
- - setGenovly: sender
- {
- genovly = sender;
- return self;
- }
-
- - performTesselation: sender
- {
- id imgview,outview,outimg;
- NXPoint pt,genofft;
- NXSize lsize;
- NXRect outrect;
- float xstart;
- int xlimit,ylimit;
-
- outview = [sender getOutputView];
- outimg = [outview getImage];
- [self getLatticeUnitSize: &lsize];
- [sender getImageView:&imgview withOffset: &genofft];
- if(![outimg lockFocus]) fprintf(stderr,"Couldn't lock outimg focus\n");
- PSgsave();
- PSscale(xscaling,yscaling);
- [outview getFrame: &outrect];
- #ifdef DEBUG
- fprintf(stderr,"Output rect: %f,%f,%f,%f\n",outrect.origin.x,outrect.origin.y,
- outrect.size.height,outrect.size.width);
- #endif
-
- pt.x = pt.y = 0.0;
- ylimit = (int)(outrect.size.height/lsize.height) + 2;
- do {
- PSmoveto(0.0,0.0);
- if(ylimit%2){
- pt.x -= lsize.width; /* adjust back for rhombic & poly case*/
- }
- xlimit = (int)(outrect.size.width/lsize.width) + 4;
- xstart = pt.x;
- do{
- #ifdef 0
- fprintf(stderr,"Current point %f,%f: xlimit %d\n",pt.x,pt.y,xlimit);
- #endif
- PSgsave();
- PStranslate(pt.x,pt.y);
- [self makeLatticeUnitAt: &genofft fromImage: [imgview getImage]];
- PSgrestore();
- [self rightTranslatePoint: &pt];
- } while (xlimit--);
- pt.x = xstart;
- [self upTranslatePoint: &pt];
- } while (ylimit--);
- PSgrestore();
- [outimg unlockFocus];
- return self;
- }
-
- - generator: (NXCoord) x : (NXCoord) y
- {
- [self clip: x : y];
- PSstroke();
- return self;
- }
-
- - clip: (NXCoord) x: (NXCoord) y
- {
- return self;
- }
- - (BOOL) isRigidLattice
- {
- return YES;
- }
- - rightTranslatePoint: (NXPoint *) pt
- {
- return self;
- }
-
- - upTranslatePoint: (NXPoint *)pt
- {
- return self;
- }
-
- - (NXSize *)getLatticeUnitSize: (NXSize *) size
- {
- size->width = latticesize.width;
- size->height = latticesize.height;
- return &latticesize;
- }
-
- - setScaling: (float) xscale:(float) yscale
- {
- xscaling = xscale;
- yscaling = yscale;
- return self;
- }
-
- - (float) xscaling
- {
- return xscaling;
- }
- - (float) yscaling
- {
- return yscaling;
- }
- - drawImage
- {
- [self sketchTemplate];
- return self;
- }
- - sketchTemplate
- {
- return self;
- }
- - makeLatticeUnitAt: (NXPoint *) point fromImage: srcimg
- {
- return self;
- }
- - (NXPoint *)getGeneratorOffset: (NXPoint *) pt
- {
- pt->x = pt->y = 0.0;
- return pt;
- }
-
- - (NXSize *)getGeneratorSize: (NXSize *) size
- {
- size->width = size->height = 0.0;
- return size;
- }
-
- @end
-
- int genfun () { return 1; }
- int clipper () { return 1; }
- int tesselate () { return 1;}
-
- defineps GroupSetup()
- /groupsdict 40 dict def
- groupsdict begin
- /equi { 3 sqrt mul 2 div } bind def
- /generatorcolor {0.655171 0.102771 0.629475 setrgbcolor } bind def
- /glidecolor {0.373226 0.462386 0.528733 setrgbcolor } bind def
- /reflectioncolor {0.333338 0.039216 0.237907 setrgbcolor } bind def
- /translationcolor {1 0.054903 0.101962 setrgbcolor } bind def
- /anglecolor { 0 0 1 setrgbcolor } bind def
- /latticeunitcolor { 0.5 setgray } bind def
- /scaling 1.0 def
-
- /arrow { % angle x y
- newpath moveto dup rotate
- -13 6 rlineto 4 -6 rlineto
- -4 -6 rlineto closepath gsave 0
- setlinejoin stroke grestore fill neg rotate
- } def
-
- /addpoints { % x y x y
- exch % x y y x
- 4 1 roll % y y x x
- add 3 1 roll % x y y
- add % x y
- } bind def
-
- /duptop2 { % x y -> x y x y
- dup % x y y
- 3 2 roll % y y x
- dup % y y x x
- 4 1 roll % x y y x
- exch % x y x y
- } bind def
-
- /even { % num
- cvi 1 and 1 eq not
- } bind def
-
- /setscaling { % scale - wrap with dictionary use !!!
- % groupsdict begin
- % /scaling exch def
- % [scaling 0 0 scaling 0 0] setmatrix
- % end
- pop
- } bind def
-
- /reflect { % angle
- dup rotate
- [1 0 0 -1 0 0] concat
- neg rotate
- } bind def
-
- /rhombus { % x y
- groupsdict begin
- moveto
- latticeunitcolor
- lattice:side 0 lineto
- lattice:w lattice:h rlineto
- lattice:side neg 0 rlineto
- closepath
- stroke
- end
- } bind def
-
- /transv0 { %x y len
- groupsdict begin
- gsave
- 2 setlinewidth
- translationcolor
- moveto dup 0 rlineto stroke
- 0 exch 0 arrow
- grestore
- end
- } bind def
-
- /transv90 { %x y len
- groupsdict begin
- gsave
- 2 setlinewidth
- translationcolor
- moveto dup 0 exch rlineto stroke
- 90 exch 0 exch arrow
- grestore
- } bind def
-
- /transv60 { %x y run rise
- groupsdict begin
- gsave
- 2 setlinewidth
- translationcolor
- moveto
- duptop2
- rlineto stroke
- 60 3 1 roll % angle of arrow
- arrow
- grestore
- end
- } bind def
-
- /reflectionaxis { % x1 y1 x2 y2
- groupsdict begin
- reflectioncolor
- moveto rlineto stroke
- end
- } bind def
-
- /rotation3 { % size x y
- groupsdict begin
- moveto
- /r3size exch def
- /r3ext r3size equi def
- anglecolor
- 0 r3ext 2 div rmoveto
- r3size 2 div r3ext neg rlineto
- r3size neg 0 rlineto
- closepath
- gsave fill grestore stroke
- end
- } bind def
- end
- endps
-
- defineps reflect(float angle)
- groupsdict begin
- angle reflect
- end
- endps
-